/*
 * Copyright 2020-2021 redragon-erp/赤龙ERP
 * Author redragon/dongbin
 * This file is part of redragon-erp/赤龙ERP.

 * 赤龙ERP官方声明：
 * (1)赤龙ERP的知识产权归软件著作权人所有
 * (2)未经著作权人授权，不得将赤龙ERP用于任何形式的商业用途
 * (3)对侵权的组织或个人，著作权人将保留诉诸法律的权利

 * 赤龙ERP官网详见 <https://www.redragon-erp.com>
 * 赤龙ERP仓库详见 <https://gitee.com/redragon/redragon-erp> 
 * 如遇任何问题，请与著作权人联系
 */
package com.springboot.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.redragon.framework.spring.aspect.SystemLogAspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * AOP拦截service层方法用于日志输出
 * @author dongbin
 *
 */
@Aspect
@Component
public class SystemLogAspectAOP extends SystemLogAspect {
	
	//日志处理
	private Logger logger = LoggerFactory.getLogger(SystemLogAspectAOP.class);
	
	@Pointcut("execution(* com.erp.permission.service.*.*(..))||"
	        + "execution(* com.erp.dataset.service.*.*(..))||"
	        + "execution(* com.erp.hr.service.*.*(..))||"
	        + "execution(* com.erp.masterdata.*.service.*.*(..))||"
	        + "execution(* com.erp.order.*.service.*.*(..))||"
	        + "execution(* com.erp.finance..*.service.*.*(..))||"
	        + "execution(* com.erp.common..*.service.*.*(..))||"
	        + "execution(* com.erp.ledger..*.service.*.*(..))||"
	        + "execution(* com.erp.report..*.service.*.*(..))||"
	        + "execution(* com.erp.prod..*.service.*.*(..))||"
	        + "execution(* com.erp.cux..*.service.*.*(..))||"
	        + "execution(* com.erp.inv.*.service.*.*(..))")
	public void pointcut(){}
	
	@Around("pointcut()")
	public Object doAroundAdvice(ProceedingJoinPoint jp) throws Throwable {
		//日志
		Logger logger = LoggerFactory.getLogger(jp.getTarget().getClass());
		
		//获取方法参数
		Object[] args = jp.getArgs();
		
		//返回值
		Object result = null;
		
		try{
			result = jp.proceed(args);
		}catch(Throwable e){
			logger.error("[AOP日志处理]", e);
			throw e;
		}
		
		return result;
	}

}
